package cst.a112gxl.TeacherPlatform112gxl.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

import java.util.List;

import cst.a112gxl.TeacherPlatform112gxl.R;
import cst.a112gxl.TeacherPlatform112gxl.activity.MeActivity;
import cst.a112gxl.TeacherPlatform112gxl.activity.ViewArticleActivity;
import cst.a112gxl.TeacherPlatform112gxl.bean.LoginBean;
import cst.a112gxl.TeacherPlatform112gxl.bean.CollectBean;
import cst.a112gxl.TeacherPlatform112gxl.bean.LoginBean;

/**
 * Created by Administrator on 2017/6/8/008.
 */

public class FocusAdapter extends RecyclerView.Adapter {
    private Context context;//上下文
    private LayoutInflater layoutInflater;//动态加载布局
    private List<CollectBean<LoginBean>> list;//保存要显示的数据
    private int userid;
    public FocusAdapter(Context context) {
        this.context = context;
        layoutInflater=LayoutInflater.from(context);
    }

    //2自定义：获取数据
    public void setList(List<CollectBean<LoginBean>> list) {
        this.list=list;
    }
    //3自定义：ViewHolder子类
    public class ViewHolder extends RecyclerView.ViewHolder {
        private TextView tvtitle,tvdescrrpt,tvtime;
        public ViewHolder(View itemView) {
            super(itemView);
            tvtitle=(TextView)itemView.findViewById(R.id.textView);
            tvdescrrpt=(TextView)itemView.findViewById(R.id.textView2);
            tvtime=(TextView)itemView.findViewById(R.id.textView3);
        }
    }
    //4重写：生成Item的View
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v=layoutInflater.inflate(R.layout.item,parent,false);
        return new ViewHolder(v);
    }



    //5重写：给ViewHolder中的控件填充值，设置监听
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        LoginBean loginBean = list.get(position).getBean();
        if(loginBean==null)
            return;
        final ViewHolder  viewHolder=(ViewHolder)holder;
        viewHolder.tvtitle.setText("姓名："+loginBean.getRealname());
        viewHolder.tvdescrrpt.setText("角色："+loginBean.getRolename());
        viewHolder.tvtime.setText("性别："+loginBean.getSex());
        userid = Integer.valueOf(list.get(position).getUserid());

    }
    //共有多少条目
    @Override
    public int getItemCount() {
        if(list==null)  return 0;
        else
            return list.size();
    }
}
